﻿using GBT_Tool_v4._0;
using Newtonsoft.Json.Linq;
using NLog;
using MealManagementSystem.Entity;
using System;

namespace MealManagementSystem.Business
{
    internal class UserManage
    {
        private Logger logger = LogManager.GetCurrentClassLogger();
        HttpRequest httpRequest = new HttpRequest();

        internal bool loginVerify(JObject joParam, ref string msg, ref JObject joUserInfo)
        {
            try
            {
                string resultJson = httpRequest.GBTPost(Global.host + "gbt/UserVerify/LoginVerify", joParam.ToString());
                JObject joResult = JObject.Parse(resultJson);
                JObject joResultRoot = (JObject)joResult["root"];
                logger.Info(joResultRoot);
                JArray jaResult = (JArray)joResultRoot["data"];
                msg = (string)joResultRoot["message"];
                bool state = (bool)joResultRoot["state"];
                if (state)
                {
                    joUserInfo = (JObject)jaResult[0];
                    return true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return false;
        }

        internal bool UserModifyPassword(JObject joParam, ref string msg)
        {
            try
            {
                string resultJson = httpRequest.GBTPost(Global.host + "gbt/UserVerify/ModifyUserPassword", joParam.ToString());
                JObject joResult = JObject.Parse(resultJson);
                JObject joResultRoot = (JObject)joResult["root"];
                int line = (int)joResultRoot["data"];
                bool state = (bool)joResultRoot["state"];
                msg = (string)joResultRoot["message"];
                if (state)
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return false;
        }
    }
}
